number = input("Введите четырёхзначное число: ")
if len(number) != 4 or not number.isdigit():
    print(0)
else:
    max_prime = 0
    for i in range(len(number)):
        for j in range(i+1, len(number)+1):
            sub_num = int(number[i:j])
            if sub_num > 1:
                for k in range(2, int(sub_num**0.5) + 1):
                    if sub_num % k == 0:
                        break
                else:
                    max_prime = max(max_prime, sub_num)
    print(max_prime)
